package com.xisoft.utils;

import cn.hutool.core.util.ServiceLoaderUtil;
import com.xisoft.common.bean.ReflectionUtil;
import com.xisoft.common.pubEnv.CollectionUtil;
import com.xisoft.common.pubEnv.JsonUtil;
import com.xisoft.common.pubEnv.PinYinUtil;
import com.xisoft.devise.service.EngineService;
import com.xisoft.devise.service.impl.EngineServiceImpl;
import com.xisoft.devise.service.impl.GenServiceImpl;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;

/**
 * *
 * Created with Description:
 *
 * @version 1.0 <br>
 * @packagename: com.xisoft.devise.utils<br>
 * @author: LiBencheng <br>
 * @computer: licheng <br>
 * @date: Created on 2022/8/31 16:40 <br>
 */
public class TestDemo
{
    @Test
    public void test10( ) throws Exception
    {
        ServiceLoader< EngineService > yzs = ServiceLoaderUtil.load(EngineService.class);
        System.err.println(yzs.iterator());
        yzs.forEach(obj ->
                    {
                        System.err.println(obj);
                    });
        System.err.println(yzs.getClass());
    }

    @Test
    public void test09( ) throws Exception
    {
        String json = "{\"code\":\"1\",\"value\":\"1\",\"serviceName\":\"人力服务\",\"description\":\"备注信息\"," +
                "\"type\":\"solution\"}";
        Map< String,Object > tabMap = JsonUtil.toMap(json);
    }

    @Test
    public void test08( ) throws Exception
    {
        String spelling = PinYinUtil.convertSimpleSpelling("李本城");
        System.err.println(spelling);
        spelling = PinYinUtil.convertAllSpells("李本城");
        System.err.println(spelling);
    }

    @Test
    public void test07( ) throws Exception
    {
        GenServiceImpl genService = new GenServiceImpl();
        genService.makeCode("");
    }

    @Test
    public void test06( ) throws Exception
    {
        String json = "{moduleType: form,code: hrSalaryArrearsRules}";
        json = "{moduleType: list,code: hrSalaryArrearsRulesBusiness,hrSalaryArrearsRulesList}";
        new EngineServiceImpl().generateConfig("");
    }

    @Test
    public void test05( ) throws Exception
    {
        String josn = "{name:{张三},sxe:男}";
        Map< String,Object > toMap = JsonUtil.toMap(josn);
        System.err.println(toMap);
    }

    @Test
    public void test04( ) throws Exception
    {
        Object obj = ReflectionUtil.newInstance("");
        System.err.println(obj);
        System.err.println(CollectionUtil.transBean2Map(obj));
        Object o = CollectionUtil.map2Josn(CollectionUtil.transBean2Map(obj));
        System.out.println(o);
    }

    @Test
    public void test03( ) throws Exception
    {
        Object obj = ReflectionUtil.newInstance("");
        System.err.println(obj);
        System.err.println(CollectionUtil.transBean2Map(obj));
        Object o = CollectionUtil.map2Josn(CollectionUtil.transBean2Map(obj));
        System.out.println(o);
    }

    @Test
    public void test02( ) throws Exception
    {
        String json = "{\n" +
                "    \"sdt_id\":\"主键\",\n" +
                "    \"moduleid\":\"yyds129b9ea5be8c4f348dd8f4c2a4503fa3\",\n" +
                "    \"sdt_system_name\":\"系统名称\",\n" +
                "    \"sdt_table_en_name\":\"ceshi\",\n" +
                "    \"sdt_table_type\":\"1\",\n" +
                "    \"sdt_table_zh_name\":\"ceshi\",\n" +
                "    \"type\":\"1\",\n" +
                "    \"sort\":\"0\",\n" +
                "    \"memo\":\"备注\",\n" +
                "    \"isexist\":\"false\",\n" +
                "    \"fields\":[\n" +
                "        {\n" +
                "            \"sdf_field_en_name\":\"xxyy\",\n" +
                "            \"sdf_field_zh_name\":\"xxyy\",\n" +
                "            \"sdf_field_type\":\"DXZJ\",\n" +
                "            \"sdf_field_length\":\"10\",\n" +
                "            \"sdt_system_name\":\"hr\",\n" +
                "            \"sdt_table_en_name\":\"ceshi\",\n" +
                "            \"sdf_primary_key\":\"true\",\n" +
                "            \"isnotnull\":\"0\",\n" +
                "            \"defvalue\":\"~\",\n" +
                "            \"refobject\":\"参照值\",\n" +
                "            \"isextend\":\"是否用户扩展\",\n" +
                "            \"version\":\"1.0\",\n" +
                "            \"sort\":\"0\",\n" +
                "            \"memo\":\"备注\",\n" +
                "            \"sdf_id\":\"主键\",\n" +
                "            \"sdt_id\":\"主表主键\",\n" +
                "            \"moduleid\":\"必传\",\n" +
                "            \"isexist\":\"true true时不做插入保存，否则为更新表字段\"\n" +
                "        }\n" +
                "    ]\n" +
                "}\n";

        Map< String,Object > tabMap = JsonUtil.toMap(json);
    }

    @Test
    public void test021( ) throws Exception
    {
        String json =
                "    [\n" +
                        "        {\n" +
                        "            \"reference \":\"参照\",\n" +
                        "            \"sdf_field_type\":\"DXZJ\",\n" +
                        "            \"sdf_biz_document_no\":\"业务单据号\",\n" +
                        "            \"sdt_system_name\":\"系统名\",\n" +
                        "            \"sdt_table_en_name\":\"ceshi\",\n" +
                        "            \"sdf_field_zh_name\":\"xxyy\",\n" +
                        "            \"sdf_primary_key\":\"y\",\n" +
                        "            \"sdf_id\":\"主键\",\n" +
                        "            \"sdf_field_en_name\":\"xxyy\",\n" +
                        "            \"sdf_field_length\":\"字段长度\",\n" +
                        "            \"isexist\":\"true\"\n" +
                        "        }\n" +
                        "    ]\n";

        List< Map< String,Object > > toList = JsonUtil.toList(json);
        System.out.println(toList);
    }

    @Test
    public void test01( ) throws Exception
    {
        String json = "[{\n isexist:true,\"reference\":null,\"sdf_field_type\":\"number\"," +
                "\"sdf_biz_document_no\":\"YES\"," +
                "\"sdt_system_name\":\"hr_ral\",\"sdt_table_en_name\":\"HR_SALARY_DATA\"," +
                "\"sdf_field_zh_name\":\"F_3\",\"sdf_primary_key\":\"YES\"," +
                "\"sdf_id\":\"542e7f1e-f5ad-4bac-a918-4580643e32c1\",\"sdf_field_en_name\":\"F_3\"," +
                "\"sdf_field_length\":\"38\"},{\"reference\":null,\"sdf_field_type\":\"number\"," +
                "\"sdf_biz_document_no\":\"YES\",\"sdt_system_name\":\"hr_ral\"," +
                "\"sdt_table_en_name\":\"HR_SALARY_DATA\",\"sdf_field_zh_name\":\"F_4\",\"sdf_primary_key\":\"YES\"," +
                "\"sdf_id\":\"f487d688-addd-442f-a7dc-a88a6d3d7a4c\",\"sdf_field_en_name\":\"F_4\"," +
                "\"sdf_field_length\":\"38\"},{\"reference\":null,\"sdf_field_type\":\"number\"," +
                "\"sdf_biz_document_no\":\"YES\",\"sdt_system_name\":\"hr_ral\"," +
                "\"sdt_table_en_name\":\"HR_SALARY_DATA\",\"sdf_field_zh_name\":\"F_5\",\"sdf_primary_key\":\"YES\"," +
                "\"sdf_id\":\"6380a2cc-8d4d-4e8a-8b67-3415c0bb487f\",\"sdf_field_en_name\":\"F_5\"," +
                "\"sdf_field_length\":\"38\"}]";
        List< Map< String,Object > > toList = JsonUtil.toList(json);
        System.out.println(toList);
    }
}
